﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Linq;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using LMS.SMSH.BLL;
using LMS.SMSH.MODEL;


namespace LMS.SMSH.WEB
{
    public partial class StuProject : System.Web.UI.Page
    {
        int rowNo = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["studentID"] != null)
                {
                    bingGvStuProject();
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请不要非法操作，这是不道德的行为!')", true);
                }
            }
        }

        /// <summary>
        /// 绑定gvStuProject
        /// </summary>
        private void bingGvStuProject()
        {
            gvMyProject.DataSource = LMSDataContext.GetLMSDB.sp_viewPro();
            gvMyProject.DataKeyNames = new string[] { "proId" };
            gvMyProject.DataBind();
        }

        /// <summary>
        /// 将时间按照格式(2010-10-7)显示
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        protected DateTime GetDataTimeFormat(DateTime time)
        {
            string strTime = time.ToString("yyyy-MM-dd");
            return DateTime.Parse(strTime);
        }

        /// <summary>
        /// 行数据绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvMyProject_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                rowNo++;
                //行编号
                e.Row.Cells[0].Text = (gvMyProject.PageIndex * gvMyProject.PageSize + rowNo).ToString();
                //鼠标悬停变色
                e.Row.Attributes.Add("onmouseover", "oldBG=this.style.backgroundColor;this.style.backgroundColor='#FF1199';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=oldBG;");
            }
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvMyProject_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvMyProject.PageIndex = e.NewPageIndex;
            bingGvStuProject();
        }


    }
}